package course;

import java.util.*;
import javax.jdo.annotations.*;
import department.Department;

import com.google.appengine.api.datastore.Key;
import article.*;

@PersistenceCapable
public class Course {
	
	@PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key CourseId;
	
	@Persistent
	private String CourseName;
	
	@Persistent
	private String CourseSem;
	
	@Persistent
	private Department CourseDepartment;
	
	@Persistent
	private Long CourseTeacher;
	
	@Persistent
	private String CourseOutline;
	
	@Persistent
	private int couGood;
	
	@Persistent
	private int couBad;
	
	@Persistent(mappedBy = "courseId")
	@Element(dependent = "true") 
	private List <Article> art;
	
	public Course(String name,String sem,Department dep,Long teacher,String outline){
		this.CourseName = name;
		this.CourseSem = sem;
		this.CourseDepartment = dep;
		this.CourseTeacher = teacher;
		this.CourseOutline = outline;
		this.couGood = 0;
		this.couBad = 0;
	}
	
	public Course(){
		this.CourseName = "NA";
		this.CourseSem = "NA";
		this.CourseOutline = "NA";
		this.couGood = 0;
		this.couBad = 0;
	}
	
	public Long getId(){
		return CourseId.getId();
	}
	
	public String getName(){
		return CourseName;
	}
	
	public String getSem(){
		return CourseSem;
	}
	
	public Department getDep(){
		return CourseDepartment;
	}
	
	public Long getTeacher(){
		return CourseTeacher;
	}
	
	public String getOutline(){
		return CourseOutline;
	}
	
	public int getGood(){
		return couGood;
	}
	
	public int getBad(){
		return couBad;
	}
	
	public void setName(String name){
		this.CourseName = name;
	}
	
	public void setDep(Department dep){
		this.CourseDepartment = dep;
	}
	
	public void setTeacher(Long teacher){
		this.CourseTeacher = teacher;
	}
	
	public void setSem(String sem){
		this.CourseSem = sem;
	}
	
	public void setOutline(String outline){
		this.CourseOutline = outline;
	}
	
	public void setGood(){
		this.couGood++;
	}
	
	public void setBad(){
		this.couBad++;
	}
	
	public List<Article> getAllArt(){
		List<Article> temp = new ArrayList<Article>();
		for(Article art: this.art){
			temp.add(art);
		}
		return temp;
	}
	
	public void addArt(Course course,String member,String title,String pub_time,String content){
		art.add(new Article(course,member,title,pub_time,content));
	}
}
